package com.leyou.controller;

import com.leyou.ResponseData;
import com.leyou.entity.Specification;
import com.leyou.service.SpecificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/specification")
public class SpecificationController {

    @Autowired
    private SpecificationService specificationService;

    @GetMapping("/{cid}")
    public ResponseData getSpecByCid(@PathVariable Long cid) {
        try {
            if (cid < 0) {
                return ResponseData.error(400, "请求参数有误", null);
            }
            Specification specification = specificationService.getSpecByCid(cid);
            return ResponseData.ok(specification);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseData.error();
    }
}
